package com.goodluck.goodluckim.network;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;

/**
 * Created by wyj on 2018/9/3.
 */
public class WebSocketInitializer extends ChannelInitializer<SocketChannel> {

    private WebSocketClientHandler handler;

    public WebSocketInitializer(WebSocketClientHandler handler) {
        this.handler = handler;
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(
                new HttpClientCodec(),
                new HttpObjectAggregator(8000),
                new WebSocketClientCompressionHandler(),
                handler);
    }
}
